@echo off


rem return back possible changes in reextractBeforeE.bat
if exist extdec\1093.mtp  if not exist extdec\1093.mt   move  /Y extdec\1093.mtp  extdec\1093.mt >NUL



rem no tools for extracting 0170? (btsc)



rem extract duples (those not extracted normally)
if not exist ..\extracted\td_dbattle mkdir ..\extracted\td_dbattle
FOR %%i IN (extDec\*.bt.dt)   DO ffxbt   -e4  -t ffx.tbs   %%i     "..\extracted\td_dbattle\%%~ni.txt"

rem handle specific
if exist "..\extracted\td_dbattle\1687.bt.txt"   move /Y "..\extracted\td_dbattle\1687.bt.txt"   "..\extracted\dbattle\1687.txt"  >NUL

rem compare duples
if not exist "..\extracted\dbattle\1687.txt"    diff --binary -q   "..\extracted\td_dbattle\1687.bt.txt"   "..\extracted\dbattle\1226.txt"
if not exist "..\extracted\dbattle\1813.txt"    diff --binary -q   "..\extracted\td_dbattle\1813.bt.txt"   "..\extracted\dbattle\1226.txt"
if not exist "..\extracted\dbattle\1246.txt"    diff --binary -q   "..\extracted\td_dbattle\1246.bt.txt"   "..\extracted\dbattle\1239.txt"
if not exist "..\extracted\dbattle\1249.txt"    diff --binary -q   "..\extracted\td_dbattle\1249.bt.txt"   "..\extracted\dbattle\1239.txt"
if not exist "..\extracted\dbattle\1252.txt"    diff --binary -q   "..\extracted\td_dbattle\1252.bt.txt"   "..\extracted\dbattle\1239.txt"
if not exist "..\extracted\dbattle\1257.txt"    diff --binary -q   "..\extracted\td_dbattle\1257.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1258.txt"    diff --binary -q   "..\extracted\td_dbattle\1258.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1259.txt"    diff --binary -q   "..\extracted\td_dbattle\1259.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1260.txt"    diff --binary -q   "..\extracted\td_dbattle\1260.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1261.txt"    diff --binary -q   "..\extracted\td_dbattle\1261.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1262.txt"    diff --binary -q   "..\extracted\td_dbattle\1262.bt.txt"   "..\extracted\dbattle\1256.txt"
if not exist "..\extracted\dbattle\1274.txt"    diff --binary -q   "..\extracted\td_dbattle\1274.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1275.txt"    diff --binary -q   "..\extracted\td_dbattle\1275.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1298.txt"    diff --binary -q   "..\extracted\td_dbattle\1298.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1299.txt"    diff --binary -q   "..\extracted\td_dbattle\1299.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1300.txt"    diff --binary -q   "..\extracted\td_dbattle\1300.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1301.txt"    diff --binary -q   "..\extracted\td_dbattle\1301.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1305.txt"    diff --binary -q   "..\extracted\td_dbattle\1305.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1306.txt"    diff --binary -q   "..\extracted\td_dbattle\1306.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1307.txt"    diff --binary -q   "..\extracted\td_dbattle\1307.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1308.txt"    diff --binary -q   "..\extracted\td_dbattle\1308.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1311.txt"    diff --binary -q   "..\extracted\td_dbattle\1311.bt.txt"   "..\extracted\dbattle\1273.txt"
if not exist "..\extracted\dbattle\1988.txt"    diff --binary -q   "..\extracted\td_dbattle\1988.bt.txt"   "..\extracted\dbattle\1348.txt"
if not exist "..\extracted\dbattle\1380.txt"    diff --binary -q   "..\extracted\td_dbattle\1380.bt.txt"   "..\extracted\dbattle\1377.txt"
if not exist "..\extracted\dbattle\1387.txt"    diff --binary -q   "..\extracted\td_dbattle\1387.bt.txt"   "..\extracted\dbattle\1377.txt"
if not exist "..\extracted\dbattle\1554.txt"    diff --binary -q   "..\extracted\td_dbattle\1554.bt.txt"   "..\extracted\dbattle\1546.txt"
if not exist "..\extracted\dbattle\1632.txt"    diff --binary -q   "..\extracted\td_dbattle\1632.bt.txt"   "..\extracted\dbattle\1631.txt"
if not exist "..\extracted\dbattle\1634.txt"    diff --binary -q   "..\extracted\td_dbattle\1634.bt.txt"   "..\extracted\dbattle\1631.txt"
if not exist "..\extracted\dbattle\1636.txt"    diff --binary -q   "..\extracted\td_dbattle\1636.bt.txt"   "..\extracted\dbattle\1631.txt"
if not exist "..\extracted\dbattle\1637.txt"    diff --binary -q   "..\extracted\td_dbattle\1637.bt.txt"   "..\extracted\dbattle\1631.txt"
if not exist "..\extracted\dbattle\1638.txt"    diff --binary -q   "..\extracted\td_dbattle\1638.bt.txt"   "..\extracted\dbattle\1631.txt"



rem duplicity to 2986
if not exist ..\extracted\td_graphic  mkdir ..\extracted\td_graphic
FOR %%i IN (extdec\2945*) DO (
    ffxgnop  -e -ta -pb 256,128,8,0x22B80  -pp 0x21360    %%i  %%i  ..\extracted\td_graphic\%%~ni_0.bmp
    ffxgnop  -e -ta -pb 256,128,8,0x2AB80  -pp 0x21760    %%i  %%i  ..\extracted\td_graphic\%%~ni_1.bmp
    ffxgnop  -e -ta -pb 256,128,8,0x32B80  -pp 0x21B60    %%i  %%i  ..\extracted\td_graphic\%%~ni_2.bmp
    ffxgnop  -e -ta -pb 256,128,8,0x3AB80  -pp 0x21F60    %%i  %%i  ..\extracted\td_graphic\%%~ni_3.bmp
    ffxgnop  -e -ta -pb 256,128,8,0x42B80  -pp 0x22360    %%i  %%i  ..\extracted\td_graphic\%%~ni_4.bmp
    ffxgnop  -e -ta -pb 256,128,8,0x4AB80  -pp 0x22760    %%i  %%i  ..\extracted\td_graphic\%%~ni_5.bmp
)
diff --binary -q   ..\extracted\graphic\2986_0.bmp   ..\extracted\td_graphic\2945_0.bmp
diff --binary -q   ..\extracted\graphic\2986_1.bmp   ..\extracted\td_graphic\2945_1.bmp
diff --binary -q   ..\extracted\graphic\2986_2.bmp   ..\extracted\td_graphic\2945_2.bmp
diff --binary -q   ..\extracted\graphic\2986_3.bmp   ..\extracted\td_graphic\2945_3.bmp
diff --binary -q   ..\extracted\graphic\2986_4.bmp   ..\extracted\td_graphic\2945_4.bmp
diff --binary -q   ..\extracted\graphic\2986_5.bmp   ..\extracted\td_graphic\2945_5.bmp

rem duplicity for EV graphic
if not exist ..\extracted\td_graphic  mkdir ..\extracted\td_graphic
ffxgnop  -e -ta  -pb 256,128,8,0x6F80   -pp 0xEF80,16,16,0,1     extdec\0513.ev  extdec\0513.ev  ..\extracted\td_graphic\0513.bmp
ffxgnop  -e -ta  -pb 256,128,8,0x1C940  -pp 0x24940,16,16,0,1    extdec\1023.ev  extdec\1023.ev  ..\extracted\td_graphic\1023.bmp
ffxgnop  -e -ta  -pb 256,256,8,0x3660   -pp 0x13660,16,16,0,1    extdec\1025.ev  extdec\1025.ev  ..\extracted\td_graphic\1025.bmp
ffxgnop  -e -ta  -pb 256,128,8,0x80140  -pp 0x88140,16,16,0,1    extdec\1029.ev  extdec\1029.ev  ..\extracted\td_graphic\1029.bmp
ffxgnop  -e -ta  -pb 256,128,8,0x9C1A0  -pp 0xA41A0,16,16,0,1    extdec\1031.ev  extdec\1031.ev  ..\extracted\td_graphic\1031.bmp
ffxgnop  -e -ta  -pb 256,128,8,0xABA0   -pp 0x12BA0,16,16,0,1    extdec\1070.ev  extdec\1070.ev  ..\extracted\td_graphic\1070.bmp
diff --binary -q   ..\extracted\td_graphic\0513.bmp   ..\extracted\graphic\0348.bmp
diff --binary -q   ..\extracted\td_graphic\1023.bmp   ..\extracted\graphic\0739.bmp
diff --binary -q   ..\extracted\td_graphic\1025.bmp   ..\extracted\graphic\0547.bmp
diff --binary -q   ..\extracted\td_graphic\1029.bmp   ..\extracted\graphic\0348.bmp
diff --binary -q   ..\extracted\td_graphic\1031.bmp   ..\extracted\graphic\0348.bmp
diff --binary -q   ..\extracted\td_graphic\1070.bmp   ..\extracted\graphic\0739.bmp



rem duplicity in 3650
if not exist ..\extracted\td_gworld  mkdir ..\extracted\td_gworld
if exist extdec\3650.map (
    ffxmap  -e  -r 12-25   extdec\3650.map   ..\extracted\td_gworld\3650_
    ffxmap  -e  -r 27      extdec\3650.map   ..\extracted\td_gworld\3650_
    ffxmap  -e  -r 31-44   extdec\3650.map   ..\extracted\td_gworld\3650_
)
rem 30 same as 27, 30-44 same
FOR %%i IN (27 31 32 33 34 35 36 37 38 39 40 41 42 43 44) DO (
    diff --binary -q   ..\extracted\gworld\3650_30.bmp   ..\extracted\td_gworld\3650_%%~ni.bmp 
)
rem 11 same as 12-25
FOR %%i IN (12 13 14 15 16 17 18 19 20 21 22 23 24 25) DO (
    diff --binary -q   ..\extracted\gworld\3650_11_01.bmp  ..\extracted\td_gworld\3650_%%~ni_01.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_02.bmp  ..\extracted\td_gworld\3650_%%~ni_02.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_03.bmp  ..\extracted\td_gworld\3650_%%~ni_03.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_04.bmp  ..\extracted\td_gworld\3650_%%~ni_04.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_05.bmp  ..\extracted\td_gworld\3650_%%~ni_05.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_06.bmp  ..\extracted\td_gworld\3650_%%~ni_06.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_07.bmp  ..\extracted\td_gworld\3650_%%~ni_07.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_08.bmp  ..\extracted\td_gworld\3650_%%~ni_08.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_09.bmp  ..\extracted\td_gworld\3650_%%~ni_09.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_10.bmp  ..\extracted\td_gworld\3650_%%~ni_10.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_11.bmp  ..\extracted\td_gworld\3650_%%~ni_11.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_12.bmp  ..\extracted\td_gworld\3650_%%~ni_12.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_13.bmp  ..\extracted\td_gworld\3650_%%~ni_13.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_14.bmp  ..\extracted\td_gworld\3650_%%~ni_14.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_15.bmp  ..\extracted\td_gworld\3650_%%~ni_15.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_16.bmp  ..\extracted\td_gworld\3650_%%~ni_16.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_17.bmp  ..\extracted\td_gworld\3650_%%~ni_17.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_18.bmp  ..\extracted\td_gworld\3650_%%~ni_18.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_19.bmp  ..\extracted\td_gworld\3650_%%~ni_19.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_20.bmp  ..\extracted\td_gworld\3650_%%~ni_20.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_21.bmp  ..\extracted\td_gworld\3650_%%~ni_21.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_22.bmp  ..\extracted\td_gworld\3650_%%~ni_22.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_23.bmp  ..\extracted\td_gworld\3650_%%~ni_23.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_24.bmp  ..\extracted\td_gworld\3650_%%~ni_24.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_25.bmp  ..\extracted\td_gworld\3650_%%~ni_25.bmp
    diff --binary -q   ..\extracted\gworld\3650_11_26.bmp  ..\extracted\td_gworld\3650_%%~ni_26.bmp
)
rem duplicity to 3650
rem extracting 3640 with same name as 3650 for better compare
if not exist ..\extracted\td_gworld3640  mkdir ..\extracted\td_gworld3640
if exist extdec\3640.map (
    rem must extract only those for compare
    ffxmap  -e  -r 0           extdec\3640.map   ..\extracted\td_gworld3640\3650_
    ffxmap  -e  -r 3-4,1-26    extdec\3640.map   ..\extracted\td_gworld3640\3650_
    ffxmap  -e  -r 5-6         extdec\3640.map   ..\extracted\td_gworld3640\3650_
    ffxmap  -e  -r 11-25,1-26  extdec\3640.map   ..\extracted\td_gworld3640\3650_
    ffxmap  -e  -r 27          extdec\3640.map   ..\extracted\td_gworld3640\3650_
    ffxmap  -e  -r 29-44       extdec\3640.map   ..\extracted\td_gworld3640\3650_
)
rem some hacks to better compare (update palette to be same)
fcopy -idx ..\extracted\td_gworld3640\3650_29_00.bmp  0x0342 00FF0000
fcopy -idx ..\extracted\td_gworld3640\3650_29_01.bmp  0x0342 00FF0000
if not exist  ..\extracted\td_gworld3640\3650_*.bmp  echo ERROR: must exist "..\extracted\td_gworld3640\3650_*.bmp"
FOR %%i IN (..\extracted\td_gworld3640\3650_*.bmp) DO (
    if exist  ..\extracted\gworld\%%~nxi      diff --binary -q   %%i   ..\extracted\gworld\%%~nxi
    if exist  ..\extracted\td_gworld\%%~nxi   diff --binary -q   %%i   ..\extracted\td_gworld\%%~nxi
)


